package com.czk.date;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/11/23 9:54
 */
public class DateTransferUtil {
    public static void main(String[] args) {
        Date date=new Date();
        LocalDateTime localDateTime = dateToLocalDateTime(date);

        Date date1 = localDateToDate(localDateTime);



    }
    /**
     * date转LocalDateTime
     *
     * @param date
     * @return
     */
    public static LocalDateTime dateToLocalDateTime(Date date) {
        LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
        return localDateTime;
    }

    /**
     * localDateTime转date
     *
     * @param localDateTime
     * @return
     */
    public static Date localDateToDate(LocalDateTime localDateTime) {
        Date date = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
        return date;
    }
}
